package config

import (
	"errors"
	"github.com/aliyun/credentials-go/credentials"
	"os"
)

func GetKS() (credentials.Credential, error) {
	key, ok := os.LookupEnv("ALIYUN_KEY")
	if !ok {
		return nil, errors.New("未获取到key")
	}
	secret, ok := os.LookupEnv("ALIYUN_SECRET")
	if !ok {
		return nil, errors.New("未获取到secret")
	}
	config := &credentials.Config{}
	config.SetType("access_key").SetAccessKeyId(key).SetAccessKeySecret(secret)

	credential, err := credentials.NewCredential(config)
	if err != nil {
		return nil, err
	}
	return credential, nil
}
